package com.iring.vo;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

/**
 * 分页参数vo
 *
 * @author wanggan
 */
public class PageableVO {

    private int number;

    private int size;

    private SortVO sort;

    @Override
    public String toString() {
        return "{number:" + number + ",size:" + size + ",sort:" + sort + "}";
    }

    public PageRequest pageRequest() {
        if (null == sort || sort.getOrder() == null || sort.getOrder()
                .length() < 1) {
            return new PageRequest(number, size);
        } else {
            return new PageRequest(number, size, new Sort(sort.getDirection(), sort.getOrder()));
        }
    }

    public int getNumber() {
        return number;
    }

    public int getSize() {
        return size;
    }

    public SortVO getSort() {
        return sort;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public void setSort(SortVO sort) {
        this.sort = sort;
    }

}
